package com.gf.gf_data.service.impl;

import com.gf.gf_data.dao.MtChartBarKDao;
import com.gf.gf_data.entity.MtChartBarK;
import com.gf.gf_data.service.MtChartBarKService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Eternal_L on 2018/1/10.
 */
@Service
public class MtChartBarKServiceImpl implements MtChartBarKService {

    private final MtChartBarKDao mtChartBarKDao;

    @Autowired
    public MtChartBarKServiceImpl(MtChartBarKDao mtChartBarKDao) {
        this.mtChartBarKDao = mtChartBarKDao;
    }

    @Override
    public List<Map<String, Object>> getLatestMtChartBarK1Info(String symbol, Integer limit) {
        if (limit == null || limit <= 0) limit = 20;
        List<Map<String, Object>> result = new LinkedList<>();

        List<MtChartBarK> latestList = mtChartBarKDao.listLatestM1K(symbol, limit);

        if (latestList.size() > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("symbol", symbol);
            map.put("section", "M1");
            map.put("length", 15);
            map.put("k_data", latestList.subList(0, 15));
            map.put("type", "current");
            map.put("similarity", 100);
            result.add(map);

            Map<String, Object> map1 = new HashMap<>();
            map1.put("symbol", symbol);
            map1.put("section", "M1");
            map1.put("length", 20);
            map1.put("k_data", latestList);
            map1.put("type", "history");
            map1.put("similarity", 88);
            result.add(map1);

            Map<String, Object> map2 = new HashMap<>();
            map2.put("symbol", symbol);
            map2.put("section",20);
            map2.put("k_data", latestList);
            map2.put("type", "history");
            map2.put("similarity", 89);
            result.add(map2);

            Map<String, Object> map3 = new HashMap<>();
            map3.put("symbol", symbol);
            map3.put("section", "M1");
            map3.put("length", 20);
            map3.put("k_data", latestList);
            map3.put("type", "history");
            map3.put("similarity", 91);
            result.add(map3);

        } else {
            return null;
        }

        return result;
    }

    @Override
    public List<Map<String, Object>> getLatestMtChartBarK1Info(String symbol, String section, Integer limit) {
        if (limit == null || limit <= 0) limit = 20;
        List<Map<String, Object>> result = new LinkedList<>();

        List<MtChartBarK> latestList = mtChartBarKDao.listLatestM1K(symbol, limit);

        if (latestList.size() > 0) {
            Map<String, Object> map = new HashMap<>();
            map.put("symbol", symbol);
            map.put("section", section);
            map.put("length", 15);
            map.put("k_data", latestList.subList(0, 15));
            map.put("type", "current");
            map.put("similarity", 100);
            result.add(map);

            Map<String, Object> map1 = new HashMap<>();
            map1.put("symbol", symbol);
            map1.put("section", section);
            map1.put("length", 20);
            map1.put("k_data", latestList);
            map1.put("type", "history");
            map1.put("similarity", 88);
            result.add(map1);

            Map<String, Object> map2 = new HashMap<>();
            map2.put("symbol", symbol);
            map2.put("section", section);
            map2.put("length", 20);
            map2.put("k_data", latestList);
            map2.put("type", "history");
            map2.put("similarity", 89);
            result.add(map2);

            Map<String, Object> map3 = new HashMap<>();
            map3.put("symbol", symbol);
            map3.put("section", section);
            map3.put("length", 20);
            map3.put("k_data", latestList);
            map3.put("type", "history");
            map3.put("similarity", 91);
            result.add(map3);

        } else {
            return null;
        }

        return result;
    }
}
